﻿using System;
using System.Collections.Generic;
using System.Text;
using Telerik.Web.UI;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Acms.WebControls
{
    public class RadGridEditColumn : GridColumn
    {
        //public ActionButton.ActionButtonIcons Icon;

        /*public override void PrepareCell(System.Web.UI.WebControls.TableCell cell, GridItem item)
        {
            base.PrepareCell(cell, item);
            if (item is GridDataItem)
            {
                foreach (Control ctrl in cell.Controls)
                {
                    ActionButton tmp = ctrl as ActionButton;
                    if (tmp != null)
                    {
                        tmp.Icon = this.Icon;

                        if (tmp.CommandName == "Edit")
                        {
                            tmp.CssClass = "edit";
                        }
                        else if (tmp.CommandName == "Update" || tmp.CommandName == "PerformInsert")
                        {
                            tmp.CssClass = "save";
                        }
                        else if (tmp.CommandName == "Cancel")
                        {
                            tmp.CssClass = "cancel";
                        }
                    }
                }
            }
        }*/

        public override GridColumn Clone()
        {
            return new RadGridEditColumn();
        }

        public override void InitializeCell(TableCell cell, int columnIndex, GridItem inItem)
        {
            if (inItem is GridHeaderItem || inItem is GridFooterItem)
            {
                base.InitializeCell(cell, columnIndex, inItem);
            }
            else if (inItem.IsInEditMode)
            {
                LinkButton btnSave = new LinkButton();
                btnSave.Text = inItem is GridDataInsertItem ? "Insert" : "Update";
                btnSave.CausesValidation = true;
                btnSave.CommandName = inItem is GridDataInsertItem ? "PerformInsert" : "Update";
                cell.Controls.Add(btnSave);

                LinkButton btnCancel = new LinkButton();
                btnCancel.Text = "Cancel";
                btnCancel.CausesValidation = false;
                btnCancel.CommandName = "Cancel";
                cell.Controls.Add(btnCancel);
            }
            else if (inItem is GridDataItem)
            {
                LinkButton btnEdit = new LinkButton();
                btnEdit.Text = "Edit";
                btnEdit.CausesValidation = true;
                btnEdit.CommandName = "Edit";
                cell.Controls.Add(btnEdit);
            }
        }
    }
}
